<extend name="layout/main" />

<block name="HEADER">

</block>

<block name="CONTENT">
    <control:grid  id="grid" padding="0" />
</block>

<block name="FOOTER">
    <script type="text/javascript">
    	var page=(function(ns){
    
		    ns.templet =function(e){
		        var src = '<i class="iconfont" style="line-height: 0;font-size: 14px;">';
		        src += e.parent_org_id == 0 ? "&#xe641;" : '&#xe66b;';
		        src += '</i> ';
		        src += e.value;
		       return  src;
		    }
		    
		    //页面初始化
		    ns.init=function(){
		        grid.loadSuccess(function(){
		            grid.setHeadHtml('<i class="iconfont icon-zhankai" onclick="page.opne()"></i>');
		        });
		    }
		    
		    //展开和收缩
		    ns.is_open = true;
		    ns.opne=function(){
		        ns.is_open = !ns.is_open;
		       $.each(grid.getRows(), function(index,o) {
		            grid.getObj().treeNodeOpen(o,ns.is_open); 
		        });
		    }
		   	
		   	//授权
		    ns.authorize=function(){
		    	var selectedRow=grid.getSelectedRows()[0];
		        var filter={
		            url: $.getModule('authorize'),
		            oid:selectedRow.org_id,
		            mode:1,
		        }
		        $.openIframe(filter, "授权",['850px', '560px']);
		    }
		   	
		    //新增
		    ns.add=function(){
		        var filter={
		            url: $.getModule('edit'),
		            oid:"",
		            mode:1,
		            nav_pid:0
		        }
		        $.openIframe(filter, "新增父页面",['350px', '300px']);
		    }
		    
		    //编辑
		    ns.edit=function(){
		        var selectedRow=grid.getSelectedRows()[0];
		        var filter={
		            url: $.getModule('edit') ,
		            oid:selectedRow.org_id,
		            mode:2
		        }
		        $.openIframe(filter, "编辑父页面",['350px', '300px']); 
		    }
		    
		    //删除
		    ns.del=function(){
		    	if(grid.getSelectedRows()[0].children[0]){
		    		return $.toast(0,'存在子角色，不能删除！');
		    	}
		        grid.deleteSelectRow();
		    }
		    
		    //新增子页面
		    ns.addSeed=function(){
		        var selectedRow=grid.getSelectedRows()[0];
		        if(!selectedRow){
		            $.toast(0,"请先选择父页面数据！");
		            return;
		        }
		        var filter={
		            url: $.getModule('edit') ,
		            oid:"",
		            mode:1,
		            parent_org_id:selectedRow.org_id,
		            parent_org_name:selectedRow.parent_org_name
		        }
		        $.openIframe(filter, "新增子页面",['350px', '300px']); 
		    }
		    
		    //移动
		    ns.move=function(mode){
		        var grids=grid;
		        if(mode>1){
		            grids = seedGrid;
		            mode =  mode == 2 ? 0 : 1;
		        }
		        var selectedRow=grids.getSelectedRows();
		        if(!selectedRow[0]){
		            $.toast(0,"请先选择数据！");
		            return;
		        }
		        if(selectedRow.length>1){
		            $.toast(0,"只能选择一条数据！");
		            return;
		        }
		        var rows = $.map(grids.getRows(),h=>{
		            if(selectedRow[0]._level == h._level) return h;
		        });
		        var coverId=-1;
		        rows.forEach(function(h,index){
		            if(selectedRow[0].org_id == h.org_id){
		                if(mode==0){
		                    if(rows[index-1]){
		                        coverId = rows[index-1].org_id;
		                    }
		                }else{
		                    if(rows[index+1]){
		                        coverId = rows[index+1].org_id;
		                    }
		                }
		            }
		        });
		        var param={ moveId:selectedRow[0].org_id, coverId:coverId}
		        $.ajaxs("/admin/soft/group/sortMove",param,function(res){
		            grids.load()
		        });
		    }
		    
		    
		    return ns;
		}({}));
		
		$(function(){ page.init();  })
    </script>
</block>



